* --------------------- *
* This file loads the child level data to compute the multigenerational effects
* presented in Table 6.
* Author: Victor Ronda
* Date Created: 01 Mar 2020
* Last Update: 22 Jan 2023
* --------------------- *



clear all
set more off

**************************
*** Health and Dominance Measures ***
**************************
use "offspring_data.dta", replace

rename health_issue_m_10m3y hi_m_13
rename dominance_relative_rank dom_pct


replace hi_m_13=1-hi_m_13
replace hi_m_13=. if obs_10m3y<=5

xtile mcoh1=mom_cohort if hi_m_13 ~=.,n(20)
xtile coh1=cohort if hi_m_13 ~=.,n(20)

local controls1 "coh1 female primip obs_10m3y"
local controls2 "mcoh1 mom_primip coh1 female primip"
local controls3 "mcoh1 mom_primip coh1 female primip obs_10m3y"

xtile mcoh3=mom_cohort if dom_pct ~=.,n(20)
xtile coh3=cohort if dom_pct ~=.,n(20)

local controls5 "coh3 female primip agedom"
local controls6 "mcoh3 mom_primip coh3 female primip"
local controls7 "mcoh3 mom_primip coh3 female primip agedom"

keep if rear_inte~=.
gen treat0=(rear_inte==0)
gen treat1=(rear_inte==1)
gen treat2=(rear_inte==2)
gen treat3=(rear_inte==3)

keep if rear_inte~=.
foreach var of varlist  hi_m_13 dom_pct{
gen a=0
replace a=1 if `var'~=.
logit a cohort female mom_cohort mom_primip primip
predict ahat_`var'
drop a
}



**** Estimation of Different Treatment Effects ***
foreach var of varlist hi_m_13 {
eststo clear

qui eststo r3_6_`var': reg `var' treat0 treat1 treat2 `controls3', vce(cl mom_id) 
qui eststo r2_6_`var': reg `var' treat0 treat1 treat3 `controls3',  vce(cl mom_id)  
qui eststo r1_6_`var': reg `var' treat0 treat2 treat3 `controls3', vce(cl mom_id) 

qui reg `var' treat0 treat1 treat2 `controls3', vce(cl mom_id)   
qui eststo rdif_6_`var': nlcom _b[treat0]-_b[treat1]-_b[treat2], post
}



foreach var of varlist dom_pct {

qui eststo r3_6_`var': reg `var' treat0 treat1 treat2 `controls7', vce(cl mom_id) 
qui eststo r2_6_`var': reg `var' treat0 treat1 treat3 `controls7', vce(cl mom_id)  
qui eststo r1_6_`var': reg `var' treat0 treat2 treat3 `controls7', vce(cl mom_id)  

qui reg `var' treat0 treat1 treat2 `controls7', vce(cl mom_id)
qui eststo rdif_6_`var': nlcom _b[treat0]-_b[treat1]-_b[treat2], post
}

*********************
****** Table 6 ******
*********************

estout r3_6_* , keep(treat1)  cells(b(fmt(3)) p(par([ ]) fmt(3))) label style(tex) starlevels( * 0.1 ** 0.05 *** 0.01) replace collabels(,none) mlabels("" "" "" "" "" "") eqlabel("" "") varlabels(treat1 "$\Psi(s_{0,1})-\Psi(s_{0,0})$" )
estout r2_6_* , keep(treat0)  cells(b(fmt(3)) p(par([ ]) fmt(3))) label style(tex) starlevels( * 0.1 ** 0.05 *** 0.01) replace collabels(,none) mlabels("" "" "" "" "" "") eqlabel("" "") varlabels(treat0 "$\Psi(s_{1,1})-\Psi(s_{1,0})$" )
estout r3_6_* , keep(treat2)  cells(b(fmt(3)) p(par([ ]) fmt(3))) label style(tex) starlevels( * 0.1 ** 0.05 *** 0.01) replace collabels(,none) mlabels("" "" "" "" "" "") eqlabel("" "") varlabels(treat2 "$\Psi(s_{1,0})-\Psi(s_{0,0})$" )
estout r1_6_* , keep(treat0)  cells(b(fmt(3)) p(par([ ]) fmt(3))) label style(tex) starlevels( * 0.1 ** 0.05 *** 0.01) replace collabels(,none) mlabels("" "" "" "" "" "") eqlabel("" "") varlabels(treat0 "$\Psi(s_{1,1})-\Psi(s_{0,1})$" )
estout r1_6_* , keep(treat2)  cells(b(fmt(3)) p(par([ ]) fmt(3))) label style(tex) starlevels( * 0.1 ** 0.05 *** 0.01) replace collabels(,none) mlabels("" "" "" "" "" "") eqlabel("" "") varlabels(treat2 "$\Psi(s_{1,0})-\Psi(s_{0,1})$" )
estout r3_6_* , keep(treat0)  cells(b(fmt(3)) p(par([ ]) fmt(3))) label style(tex) starlevels( * 0.1 ** 0.05 *** 0.01) replace collabels(,none) mlabels("" "" "" "" "" "") eqlabel("" "") varlabels(treat0 "$\Psi(s_{1,1})-\Psi(s_{0,0})$" )
estout rdif_6_* , cells(b(fmt(3)) p(par([ ]) fmt(3))) label style(tex) starlevels( * 0.1 ** 0.05 *** 0.01) replace collabels(,none) mlabels("" "" "" "" "" "") eqlabel("" "") varlabels(_nl_1 "$ [\Psi(s_{1,1})-\Psi(s_{0,1})] -[\Psi(s_{1,0})-\Psi(s_{0,0})] $" )


















